// pages/reply/reply.js
import { Reply } from './reply-model.js';
var reply = new Reply();
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id = options.id;
    this.data.id = id;
    var nickname = options.nickname;
    this.setData({
      nickname: nickname
    })
  },

  formSubmit: function (e) {
    var that = this;
    if (!e.detail.value.content) {
      wx.showToast({
        title: '请输入评论内容',
        icon: 'none',
        duration: 2000
      })
      return false;
    }
    if (e.detail.value.content.length > 100) {
      wx.showToast({
        title: '评论内容不能超过100字',
        icon: 'none',
        duration: 2000
      })
      return false;
    }
    reply.replyComments(this.data.id, e.detail.value, (data) => {
      if (data.code) {
        wx.navigateBack();
      } else {
        wx.showToast({
          title: data.error,
          icon: 'none',
          duration: 1000
        })
      }
    })
  },

})